package MyBinaryTree;

public class MyBinarySearchTree<T extends Comparable<T>> {
	private TreeNode<T> root=null;
	private int count=0;
	
	public MyBinarySearchTree(T[] array){
		insertValue(array,root);
	}
	
	public void insertValue(T[] values , TreeNode<T > next){
		for (int i=0;i<values.length;++i){
			insertValue(values[i]);
		}
	}
	
	public void insertValue(T value){
		if (root==null){
			root=new TreeNode<T>(value);
			return;
		}
		insertValue(value,root);
	}
	@SuppressWarnings("unchecked")
	private void insertValue(T value , TreeNode<T > next){
/*		if (value.compareTo(next.getData())<0){
			if ()
		}*/
	}
	
	
	public int searchValue(T value){
		count=0;
		searchValue(value,root);
		return count;
	}
	
	private TreeNode<T> searchValue(T value , TreeNode<T> next){
		if (next==null){
			return null;
		}
		
		if(next.getData().compareTo(value)>0){
			++count;
			searchValue(value,next);
		}else if (next.getData().compareTo(value)<0){
			++count;
			searchValue(value,next);
		}
		
		return next;
	}
	
	public void midOrder(){
		midOrder(root);
	}
	private void midOrder(TreeNode<T> node){
		if (node==null){
			return;
		}
		
		midOrder(node.getLeft());
		System.out.println(node.getData());
		midOrder(node.getRight());
	}

}
